package com.apestech.framework.util;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Formatter;
import java.util.Locale;
import java.util.Properties;

/**
 * @author hup
 * @create 2018-09-03-9:21
 */
public class Sys {

    public class SysInfo {
        private String ip;
        private String mac;
        private String hostName;
        private String osName;
        private String osVersion;
        private String osArch;
        private String javaVersion;
        private String javaVendor;
        private String javaVendorUrl;
        private String javaHome;
        private String javaVMSpecVersion;
        private String javaVMSpecVendor;
        private String javaVMSpecName;
        private String javaVMVersion;
        private String javaVMVendor;
        private String javaVMName;
        private String javaSpecVersion;
        private String javaSpecVendor;
        private String javaSpecName;
        private String javaClassVersion;
        private String javaClassPath;
        private String javaLibraryPath;
        private String javaIoTmpDir;
        private String javaExtDirs;
        private String fileSeparator;
        private String pathSeparator;
        private String lineSeparator;
        private String userName;
        private String userHome;
        private String userDir;

        public String getIp() {
            return ip;
        }

        public void setIp(String ip) {
            this.ip = ip;
        }

        public String getMac() {
            return mac;
        }

        public void setMac(String mac) {
            this.mac = mac;
        }

        public String getHostName() {
            return hostName;
        }

        public void setHostName(String hostName) {
            this.hostName = hostName;
        }

        public String getOsName() {
            return osName;
        }

        public void setOsName(String osName) {
            this.osName = osName;
        }

        public String getOsVersion() {
            return osVersion;
        }

        public void setOsVersion(String osVersion) {
            this.osVersion = osVersion;
        }

        public String getOsArch() {
            return osArch;
        }

        public void setOsArch(String osArch) {
            this.osArch = osArch;
        }

        public String getJavaVersion() {
            return javaVersion;
        }

        public void setJavaVersion(String javaVersion) {
            this.javaVersion = javaVersion;
        }

        public String getJavaVendor() {
            return javaVendor;
        }

        public void setJavaVendor(String javaVendor) {
            this.javaVendor = javaVendor;
        }

        public String getJavaVendorUrl() {
            return javaVendorUrl;
        }

        public void setJavaVendorUrl(String javaVendorUrl) {
            this.javaVendorUrl = javaVendorUrl;
        }

        public String getJavaHome() {
            return javaHome;
        }

        public void setJavaHome(String javaHome) {
            this.javaHome = javaHome;
        }

        public String getJavaVMSpecVersion() {
            return javaVMSpecVersion;
        }

        public void setJavaVMSpecVersion(String javaVMSpecVersion) {
            this.javaVMSpecVersion = javaVMSpecVersion;
        }

        public String getJavaVMSpecVendor() {
            return javaVMSpecVendor;
        }

        public void setJavaVMSpecVendor(String javaVMSpecVendor) {
            this.javaVMSpecVendor = javaVMSpecVendor;
        }

        public String getJavaVMSpecName() {
            return javaVMSpecName;
        }

        public void setJavaVMSpecName(String javaVMSpecName) {
            this.javaVMSpecName = javaVMSpecName;
        }

        public String getJavaVMVersion() {
            return javaVMVersion;
        }

        public void setJavaVMVersion(String javaVMVersion) {
            this.javaVMVersion = javaVMVersion;
        }

        public String getJavaVMVendor() {
            return javaVMVendor;
        }

        public void setJavaVMVendor(String javaVMVendor) {
            this.javaVMVendor = javaVMVendor;
        }

        public String getJavaVMName() {
            return javaVMName;
        }

        public void setJavaVMName(String javaVMName) {
            this.javaVMName = javaVMName;
        }

        public String getJavaSpecVersion() {
            return javaSpecVersion;
        }

        public void setJavaSpecVersion(String javaSpecVersion) {
            this.javaSpecVersion = javaSpecVersion;
        }

        public String getJavaSpecVendor() {
            return javaSpecVendor;
        }

        public void setJavaSpecVendor(String javaSpecVendor) {
            this.javaSpecVendor = javaSpecVendor;
        }

        public String getJavaSpecName() {
            return javaSpecName;
        }

        public void setJavaSpecName(String javaSpecName) {
            this.javaSpecName = javaSpecName;
        }

        public String getJavaClassVersion() {
            return javaClassVersion;
        }

        public void setJavaClassVersion(String javaClassVersion) {
            this.javaClassVersion = javaClassVersion;
        }

        public String getJavaClassPath() {
            return javaClassPath;
        }

        public void setJavaClassPath(String javaClassPath) {
            this.javaClassPath = javaClassPath;
        }

        public String getJavaLibraryPath() {
            return javaLibraryPath;
        }

        public void setJavaLibraryPath(String javaLibraryPath) {
            this.javaLibraryPath = javaLibraryPath;
        }

        public String getJavaIoTmpDir() {
            return javaIoTmpDir;
        }

        public void setJavaIoTmpDir(String javaIoTmpDir) {
            this.javaIoTmpDir = javaIoTmpDir;
        }

        public String getJavaExtDirs() {
            return javaExtDirs;
        }

        public void setJavaExtDirs(String javaExtDirs) {
            this.javaExtDirs = javaExtDirs;
        }

        public String getFileSeparator() {
            return fileSeparator;
        }

        public void setFileSeparator(String fileSeparator) {
            this.fileSeparator = fileSeparator;
        }

        public String getPathSeparator() {
            return pathSeparator;
        }

        public void setPathSeparator(String pathSeparator) {
            this.pathSeparator = pathSeparator;
        }

        public String getLineSeparator() {
            return lineSeparator;
        }

        public void setLineSeparator(String lineSeparator) {
            this.lineSeparator = lineSeparator;
        }

        public String getUserName() {
            return userName;
        }

        public void setUserName(String userName) {
            this.userName = userName;
        }

        public String getUserHome() {
            return userHome;
        }

        public void setUserHome(String userHome) {
            this.userHome = userHome;
        }

        public String getUserDir() {
            return userDir;
        }

        public void setUserDir(String userDir) {
            this.userDir = userDir;
        }

    }

    private SysInfo sysInfo=new SysInfo();

    //得到计算机的ip地址和mac地址
    public void getConfig() throws SocketException, UnknownHostException {
        try {
//            InetAddress address = InetAddress.getLocalHost();
//            NetworkInterface ni = NetworkInterface.getByInetAddress(address);
//            //ni.getInetAddresses().nextElement().getAddress();
//            byte[] mac = ni.getHardwareAddress();
//            String sIP = address.getHostAddress();
//            String hostName = address.getHostName().toString(); //获取本机计算机名称
//            String sMAC = null;
//            Formatter formatter = new Formatter();
//            for (int i = 0; i < mac.length; i++) {
//                sMAC = formatter.format(Locale.getDefault(), "%02X%s", mac[i],
//                        (i < mac.length - 1) ? "-" : "").toString();
//            }
//            sysInfo.setHostName(hostName);
//            sysInfo.setIp(sIP);
//            sysInfo.setMac(sMAC);

            Properties props = System.getProperties();
            sysInfo.setJavaVersion(props.getProperty("java.version"));
            sysInfo.setJavaVendor(props.getProperty("java.vendor"));
            sysInfo.setJavaVendorUrl(props.getProperty("java.vendor.url"));
            sysInfo.setJavaHome(props.getProperty("java.home"));
            sysInfo.setJavaVMSpecVersion(props.getProperty("java.vm.specification.version"));
            sysInfo.setJavaVMSpecVendor(props.getProperty("java.vm.specification.vendor"));
            sysInfo.setJavaVMSpecName(props.getProperty("java.vm.specification.name"));
            sysInfo.setJavaVMVersion(props.getProperty("java.vm.version"));
            sysInfo.setJavaVMVendor(props.getProperty("java.vm.vendor"));
            sysInfo.setJavaVMName(props.getProperty("java.vm.name"));
            sysInfo.setJavaSpecVersion(props.getProperty("java.specification.version"));
            sysInfo.setJavaSpecVendor(props.getProperty("java.specification.vender"));
            sysInfo.setJavaSpecName(props.getProperty("java.specification.name"));
            sysInfo.setJavaClassVersion(props.getProperty("java.class.version"));
            sysInfo.setJavaClassPath(props.getProperty("java.class.path"));
            sysInfo.setJavaLibraryPath(props.getProperty("java.library.path"));
            sysInfo.setJavaIoTmpDir(props.getProperty("java.io.tmpdir"));
            sysInfo.setJavaExtDirs(props.getProperty("java.ext.dirs"));
            sysInfo.setOsName(props.getProperty("os.name"));
            sysInfo.setOsArch(props.getProperty("os.arch"));
            sysInfo.setOsVersion(props.getProperty("os.version"));
            sysInfo.setFileSeparator(props.getProperty("file.separator"));
            sysInfo.setPathSeparator(props.getProperty("path.separator"));
            sysInfo.setLineSeparator(props.getProperty("line.separator"));
            sysInfo.setUserName(props.getProperty("user.name"));
            sysInfo.setUserHome(props.getProperty("user.home"));
            sysInfo.setUserDir(props.getProperty("user.dir"));
        } catch (Exception e) {
            throw e;
        }
    }

    public SysInfo getSysInfo() {
        return sysInfo;
    }
}
